#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 爬取http://finance.eastmoney.com/news/cywjh.html关键字结果页面
import requests
#import codecs
from bs4 import BeautifulSoup

fo=codecs.open("a.text","w+") #打开写入文件位置

req=requests.get('http://finance.eastmoney.com/news/cywjh.html')
bs=BeautifulSoup(req.content,'html.parser')
p_title=bs.find_all('p',attrs={'class':'title'})
for info in p_title:
	url=info.a.get('href')
	req=requests.get(url)
	bs1=BeautifulSoup(req.content,'html.parser')
	title=bs1.find('h1')
	# p_all=bs1.find_all('p')
	print title
	fo.write(str(title))
    #fo.close()